#include<bits/stdc++.h>
using namespace std;
int a[1000005],u[10000005], f[1000005];
void du()
{
	memset(u,0,sizeof(u));
	int i,j;
	for (i=1; i*i<=10000000; i++)
		for (j=i; j<=10000000/i; j++)
			if (i==j) u[i*j]++;
			else u[i*j]+=2;
}
int main()
{
	if (fopen("doancon.inp", "r")){
        freopen("doancon.inp", "r", stdin);
        freopen("doancon.out", "w", stdout);
   }
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n,k; cin>>n>>k;
	for (int i=1; i<=n; i++) cin>>a[i];
	du();
	for (int i=1; i<=n; i++) f[i]=u[a[i]];
	int max=0;
	for (int i=1; i<=n; i++)
		if (max<f[i]) max=f[i];
	int i=1,j=1,d=0, res=n+1;
	while (i<=n)
	{
		if (f[i]==max) d++;
		while (d==k){
			if (res>i+1-j) res=i+1-j;
			if (f[j]==max) d--;
			j++;
		}
		i++;
	}
	if (res!=n+1) cout<<res;
	else cout<<-1;
}
